import {observable, action} from "mobx";
import request from "../utils/request";
import * as api from "../api/api";
import {LoadHoc, loading} from '../hoc/loadHoc';

/**
 * 律政中心
 */
export default class LegalStore extends LoadHoc {
  /**
   * 首页所有律师数据
   */
  @observable AllLawyerInfo: api.YNJWTLegalCenterVOLawyerInfoMiniVO = {};
  @loading @action
  async getAllLawyerInfo(params: {
    formProvinceId?: number,
    formCityId?: number,
    formDistrictId?: number,
    formAreasOfExpertiseId?: number,
    pageIndex: number,
    pageSize: number,
    callback?: (AllLawyerInfo: api.YNJWTLegalCenterVOLawyerInfoMiniVO) => void;
  }) {
    const {formProvinceId,formCityId,formDistrictId,formAreasOfExpertiseId,pageIndex,pageSize,callback} = params;
    const AllLawyerInfo = await request(api.ApplegalCenterApiFetchParamCreactor.applegalCenterGetAllLawyerInfosAsync({
      formProvinceId,
      formCityId,
      formDistrictId,
      formAreasOfExpertiseId,
      formSkipCount: (pageIndex-1)*pageSize,
      formMaxResultCount: pageSize
    }));
    this.AllLawyerInfo = AllLawyerInfo;
    callback && callback(AllLawyerInfo);
  }

  /**
   * 律师擅长领域列表标签
   */
  @observable AreasOfExpertise: api.YNJWTLegalCenterVOAreasOfExpertiseVO = {};
  @loading @action
  async getAreasOfExpertise(params: {
    callback?: (AreasOfExpertise: api.YNJWTLegalCenterVOAreasOfExpertiseVO) => void;
  }) {
    const {callback} = params;
    const AreasOfExpertise = await request(api.ApplegalCenterApiFetchParamCreactor.applegalCenterGetAreasOfExpertiseAsync({}));
    this.AreasOfExpertise = AreasOfExpertise;
    callback && callback(AreasOfExpertise);
  }

  /**
   * 律师详情
   */
  @observable lawyerInfo: api.YNJWTLegalCenterVOLawyerInfoVO = {};
  @loading @action
  async getLawyerInfo(params: {
    id: number,
    callback?: (lawyerInfo: api.YNJWTLegalCenterVOLawyerInfoVO) => void;
  }) {
    const {id, callback} = params;
    const lawyerInfo = await request(api.ApplegalCenterApiFetchParamCreactor.applegalCenterGetLawyerInfoAsync({
      formId: id
    }));
    this.lawyerInfo = lawyerInfo;
    callback && callback(lawyerInfo);
  }

  /**
   * 省
   */
  @observable allProvince: api.YNJWTLegalCenterVOAreaVO = {};
  @loading @action
   async getAllProvince(params: {
    callback?: (allProvince: api.YNJWTLegalCenterVOAreaVO) => void;
  }) {
    const {callback} = params;
    const allProvince = await request(api.ApplegalCenterApiFetchParamCreactor.applegalCenterGetAllProvinceAsync({}));
    this.allProvince = allProvince;
    callback && callback(allProvince);
  }

  /**
   * 市
   */
  @observable allCity: api.YNJWTLegalCenterVOAreaVO = {};
  @loading @action
  async getAllCity(params: {
    id: number,
    callback?: (allCity: api.YNJWTLegalCenterVOAreaVO) => void;
  }) {
    const {id, callback} = params;
    const allCity = await request(api.ApplegalCenterApiFetchParamCreactor.applegalCenterGetAllCityAsync({
     formId: id
    }));
    this.allCity = allCity;
    callback && callback(allCity);
  }

  /**
   * 区
   */
  @observable allDistrict: api.YNJWTLegalCenterVOAreaVO = {};
  @loading @action
  async getAllDistrict(params: {
    id:number,
    callback?: (allDistrict: api.YNJWTLegalCenterVOAreaVO) => void;
  }) {
    const {id, callback} = params;
    const allDistrict = await request(api.ApplegalCenterApiFetchParamCreactor.applegalCenterGetAllDistrictAsync({
      formId: id
    }));
    this.allDistrict = allDistrict;
    callback && callback(allDistrict);
  }
}
